<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

   <!-- 百度联盟 -->
   <meta name="baidu_union_verify" content="46e227ad81d5513c6cd8288c18c6ebad">

   <!-- google analytics -->
   <meta name="google-site-verification" content="SzCGQVmA8Mtk40elee-bCGpq2YSCAmEulSNEZHYCkFc" />

   <!--百度站长之家验证-->
   <meta name="baidu-site-verification" content="4woRik4rfk" />

   <meta name="description" content="坑要一个个填，路要一步步走！—— from zhisheng的博客">
   <meta name="keywords" content="Java,架构,后端,服务端,RocketMQ,分布式消息队列,分布式存储,技术博客,HBase,ElasticSearch,Spring,Spring Boot,Spring Boot 2.0,Spring Cloud,Spring MVC,Java EE,前端,HTML,MyBatis,Android,Docker,Mac,Consul,Kafka,Logstash,Kibana,MySQL,Maven,Nginx,Python,RabbitMQ,ActiveMQ,JVM">


  <title>渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下） | zhisheng的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="ElasticSearch">
<meta property="og:type" content="article">
<meta property="og:title" content="渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下）">
<meta property="og:url" content="http://www.54tianzhisheng.cn/2018/08/12/es-code03/index.html">
<meta property="og:site_name" content="zhisheng的博客">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006tNbRwly1fu8gbvoubfj31hc0vlqdt.jpg">
<meta property="og:image" content="http://image.54tianzhisheng.cn/blog/180103/C6LG3mGa12.jpg">
<meta property="og:updated_time" content="2018-11-22T14:51:59.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下）">
<meta name="twitter:image" content="https://ws1.sinaimg.cn/large/006tNbRwly1fu8gbvoubfj31hc0vlqdt.jpg">
  
    <link rel="alternative" href="/atom.xml" title="zhisheng的博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/img/favicon.ico">
  
  
      <link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css">
  
  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  
  
      <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  
  <!-- 加载特效 -->
  <script src="/js/pace.js"></script>
  <link href="/css/pace/pace-theme-flash.css" rel="stylesheet" />
  <script>
      var yiliaConfig = {
          rootUrl: '/',
          fancybox: true,
          animate: true,
          isHome: false,
          isPost: true,
          isArchive: false,
          isTag: false,
          isCategory: false,
          open_in_new: true
      }
  </script>
</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            
            <img lazy-src="/img/avatar.png" class="js-avatar">
            
        </a>

        <hgroup>
          <h1 class="header-author"><a href="/">zhisheng</a></h1>
        </hgroup>

        
        <p class="header-subtitle">坑要一个个填，路要一步步走！</p>
        
        
        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/tags/Flink/">Flink</a></li>
                        
                            <li><a href="/tags/ElasticSearch/">ElasticSearch</a></li>
                        
                            <li><a href="/tags/SpringBoot/">Spring Boot</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fl wechat" target="_blank" href="wechat:zhisheng_tian" title="wechat">wechat</a>
                            
                                <a class="fl mail" target="_blank" href="mailto://zhisheng2018@gmail.com" title="mail">mail</a>
                            
                                <a class="fl github" target="_blank" href="https://github.com/zhisheng17/" title="github">github</a>
                            
                                <a class="fl zhihu" target="_blank" href="https://www.zhihu.com/people/tian-zhisheng/activities" title="zhihu">zhihu</a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <a href="/tags/AJAX/" style="font-size: 10px;">AJAX</a> <a href="/tags/ActiveMQ/" style="font-size: 10px;">ActiveMQ</a> <a href="/tags/Android/" style="font-size: 10px;">Android</a> <a href="/tags/Bootstrap/" style="font-size: 13px;">Bootstrap</a> <a href="/tags/Consul/" style="font-size: 10px;">Consul</a> <a href="/tags/Docker/" style="font-size: 11px;">Docker</a> <a href="/tags/ElasticSearch/" style="font-size: 17px;">ElasticSearch</a> <a href="/tags/Filter过滤器/" style="font-size: 10px;">Filter过滤器</a> <a href="/tags/Flink/" style="font-size: 18px;">Flink</a> <a href="/tags/GO/" style="font-size: 10px;">GO</a> <a href="/tags/Github-Page/" style="font-size: 10px;">Github Page</a> <a href="/tags/Guava/" style="font-size: 10px;">Guava</a> <a href="/tags/HBase/" style="font-size: 10px;">HBase</a> <a href="/tags/Hibernate-JPA/" style="font-size: 11px;">Hibernate JPA</a> <a href="/tags/IO/" style="font-size: 11px;">IO</a> <a href="/tags/JMM/" style="font-size: 10px;">JMM</a> <a href="/tags/JSON/" style="font-size: 10px;">JSON</a> <a href="/tags/JVM/" style="font-size: 11px;">JVM</a> <a href="/tags/Java/" style="font-size: 20px;">Java</a> <a href="/tags/Kafka/" style="font-size: 12px;">Kafka</a> <a href="/tags/Kibana/" style="font-size: 10px;">Kibana</a> <a href="/tags/LogStash/" style="font-size: 10px;">LogStash</a> <a href="/tags/Mac/" style="font-size: 10px;">Mac</a> <a href="/tags/Maven/" style="font-size: 11px;">Maven</a> <a href="/tags/MySQL/" style="font-size: 12px;">MySQL</a> <a href="/tags/Mybatis/" style="font-size: 14px;">Mybatis</a> <a href="/tags/NIO/" style="font-size: 10px;">NIO</a> <a href="/tags/Netty/" style="font-size: 10px;">Netty</a> <a href="/tags/Nginx/" style="font-size: 11px;">Nginx</a> <a href="/tags/Oracle/" style="font-size: 10px;">Oracle</a> <a href="/tags/Pyspider/" style="font-size: 10px;">Pyspider</a> <a href="/tags/Python/" style="font-size: 12px;">Python</a> <a href="/tags/RabbitMQ/" style="font-size: 11px;">RabbitMQ</a> <a href="/tags/Redis/" style="font-size: 11px;">Redis</a> <a href="/tags/RocketMQ/" style="font-size: 13px;">RocketMQ</a> <a href="/tags/Servlet/" style="font-size: 10px;">Servlet</a> <a href="/tags/Spring/" style="font-size: 12px;">Spring</a> <a href="/tags/Spring-MVC/" style="font-size: 15px;">Spring MVC</a> <a href="/tags/SpringBoot/" style="font-size: 19px;">SpringBoot</a> <a href="/tags/SpringCloud/" style="font-size: 10px;">SpringCloud</a> <a href="/tags/SpringMVC/" style="font-size: 13px;">SpringMVC</a> <a href="/tags/String/" style="font-size: 10px;">String</a> <a href="/tags/Velocity/" style="font-size: 10px;">Velocity</a> <a href="/tags/Zookeeper/" style="font-size: 10px;">Zookeeper</a> <a href="/tags/finally/" style="font-size: 10px;">finally</a> <a href="/tags/foreach/" style="font-size: 10px;">foreach</a> <a href="/tags/hexo/" style="font-size: 12px;">hexo</a> <a href="/tags/lombok/" style="font-size: 10px;">lombok</a> <a href="/tags/lua/" style="font-size: 10px;">lua</a> <a href="/tags/yilia/" style="font-size: 11px;">yilia</a> <a href="/tags/书籍/" style="font-size: 10px;">书籍</a> <a href="/tags/分布式锁/" style="font-size: 10px;">分布式锁</a> <a href="/tags/前端/" style="font-size: 12px;">前端</a> <a href="/tags/励志/" style="font-size: 10px;">励志</a> <a href="/tags/博客合集/" style="font-size: 10px;">博客合集</a> <a href="/tags/博客网站/" style="font-size: 10px;">博客网站</a> <a href="/tags/多线程/" style="font-size: 11px;">多线程</a> <a href="/tags/大数据/" style="font-size: 18px;">大数据</a> <a href="/tags/字符串/" style="font-size: 11px;">字符串</a> <a href="/tags/实习圈/" style="font-size: 10px;">实习圈</a> <a href="/tags/循环队列/" style="font-size: 10px;">循环队列</a> <a href="/tags/微服务/" style="font-size: 11px;">微服务</a> <a href="/tags/性能调优工具/" style="font-size: 10px;">性能调优工具</a> <a href="/tags/投资理财/" style="font-size: 10px;">投资理财</a> <a href="/tags/数据库/" style="font-size: 12px;">数据库</a> <a href="/tags/数据结构/" style="font-size: 13px;">数据结构</a> <a href="/tags/文件/" style="font-size: 10px;">文件</a> <a href="/tags/旋转词/" style="font-size: 10px;">旋转词</a> <a href="/tags/流式计算/" style="font-size: 18px;">流式计算</a> <a href="/tags/流控/" style="font-size: 10px;">流控</a> <a href="/tags/爬虫/" style="font-size: 12px;">爬虫</a> <a href="/tags/算法/" style="font-size: 12px;">算法</a> <a href="/tags/类加载机制/" style="font-size: 10px;">类加载机制</a> <a href="/tags/线程池/" style="font-size: 10px;">线程池</a> <a href="/tags/编码/" style="font-size: 10px;">编码</a> <a href="/tags/表达式/" style="font-size: 10px;">表达式</a> <a href="/tags/邮件发送/" style="font-size: 10px;">邮件发送</a> <a href="/tags/随笔/" style="font-size: 16px;">随笔</a> <a href="/tags/面经/" style="font-size: 16px;">面经</a>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.csdn.net/tzs_1041218129">CSDN博客</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://juejin.im/user/57510b82128fe10056ca70fc">掘金</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.iocoder.cn/?vip">芋道源码</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://fengzhaofeng.net/">冯兆峯</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.codedata.cn/">CodeData</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://investguider.com/">美股指南</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.songyawei.cn/">Linux运维工程师</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.carlzone.cn/">carl.zhao</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://dongkelun.com/">伦少的博客</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.jiangxinlingdu.com/">匠心零度</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">17.08 ~ 18.05 永辉云创基础架构组实习     2018.06 大学毕业   2018.06 ～ 现在  另一家公司各种折腾!</div>
                </section>
                
            </div>
        </div>
        <div>
            <img src="/img/wx.jpg"  alt="zhisheng" />
        </div>
    </header>
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="Me">zhisheng</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                
                    <img lazy-src="/img/avatar.png" class="js-avatar">
                
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="Me">zhisheng</a></h1>
            </hgroup>
            
            <p class="header-subtitle">坑要一个个填，路要一步步走！</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/tags/Flink/">Flink</a></li>
                
                    <li><a href="/tags/ElasticSearch/">ElasticSearch</a></li>
                
                    <li><a href="/tags/SpringBoot/">Spring Boot</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                <div class="social">
                    
                        <a class="wechat" target="_blank" href="wechat:zhisheng_tian" title="wechat">wechat</a>
                    
                        <a class="mail" target="_blank" href="mailto://zhisheng2018@gmail.com" title="mail">mail</a>
                    
                        <a class="github" target="_blank" href="https://github.com/zhisheng17/" title="github">github</a>
                    
                        <a class="zhihu" target="_blank" href="https://www.zhihu.com/people/tian-zhisheng/activities" title="zhihu">zhihu</a>
                    
                </div>
            </nav>
        </header>                
    </div>
</nav>
      <div class="body-wrap"><article id="post-es-code03" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2018/08/12/es-code03/" class="article-date">
      <time datetime="2018-08-11T16:00:00.000Z" itemprop="datePublished">2018-08-12</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下）
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ElasticSearch/">ElasticSearch</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <p><img src="https://ws1.sinaimg.cn/large/006tNbRwly1fu8gbvoubfj31hc0vlqdt.jpg" alt="006"></p>
<a id="more"></a>
<h3 id="关注我"><a href="#关注我" class="headerlink" title="关注我"></a>关注我</h3><p><img src="http://image.54tianzhisheng.cn/blog/180103/C6LG3mGa12.jpg" alt="zhisheng"></p>
<p>转载请务必注明原创地址为：<a href="http://www.54tianzhisheng.cn/2018/08/12/es-code03/">http://www.54tianzhisheng.cn/2018/08/12/es-code03/</a></p>
<h3 id="前提"><a href="#前提" class="headerlink" title="前提"></a>前提</h3><p><a href="http://www.54tianzhisheng.cn/2018/08/11/es-code02/">上篇文章</a>写完了 ES 流程启动的一部分，main 方法都入口，以及创建 Elasticsearch 运行的必须环境以及相关配置，接着就是创建该环境的节点了。</p>
<h3 id="Node-的创建"><a href="#Node-的创建" class="headerlink" title="Node 的创建"></a>Node 的创建</h3><p>看下新建节点的代码：(代码比较多，这里是比较关键的地方，我就把注释直接写在代码上面了，实在不好拆开这段代码，300 多行代码)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="title">Node</span><span class="params">(Environment environment)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>(environment, Collections.emptyList()); <span class="comment">//执行下面的代码</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">protected</span> <span class="title">Node</span><span class="params">(<span class="keyword">final</span> Environment environment, Collection&lt;Class&lt;? extends Plugin&gt;&gt; classpathPlugins)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">final</span> List&lt;Closeable&gt; resourcesToClose = <span class="keyword">new</span> ArrayList&lt;&gt;(); <span class="comment">// register everything we need to release in the case of an error</span></span><br><span class="line">    <span class="keyword">boolean</span> success = <span class="keyword">false</span>;</span><br><span class="line">    &#123;</span><br><span class="line"><span class="comment">// use temp logger just to say we are starting. we can't use it later on because the node name might not be set</span></span><br><span class="line">        Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(environment.settings()));</span><br><span class="line">        logger.info(<span class="string">"initializing ..."</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        originalSettings = environment.settings();</span><br><span class="line">        Settings tmpSettings = Settings.builder().put(environment.settings())</span><br><span class="line">            .put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build();</span><br><span class="line"></span><br><span class="line"><span class="comment">// create the node environment as soon as possible, to recover the node id and enable logging</span></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            nodeEnvironment = <span class="keyword">new</span> NodeEnvironment(tmpSettings, environment); <span class="comment">//1、创建节点环境,比如节点名称,节点ID,分片信息,存储元,以及分配内存准备给节点使用</span></span><br><span class="line">            resourcesToClose.add(nodeEnvironment);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException ex) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> IllegalStateException(<span class="string">"Failed to create node environment"</span>, ex);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">boolean</span> hadPredefinedNodeName = NODE_NAME_SETTING.exists(tmpSettings);</span><br><span class="line">        <span class="keyword">final</span> String nodeId = nodeEnvironment.nodeId();</span><br><span class="line">        tmpSettings = addNodeNameIfNeeded(tmpSettings, nodeId);</span><br><span class="line">        <span class="keyword">final</span> Logger logger = Loggers.getLogger(Node.class, tmpSettings);</span><br><span class="line"><span class="comment">// this must be captured after the node name is possibly added to the settings</span></span><br><span class="line">        <span class="keyword">final</span> String nodeName = NODE_NAME_SETTING.get(tmpSettings);</span><br><span class="line">        <span class="keyword">if</span> (hadPredefinedNodeName == <span class="keyword">false</span>) &#123;</span><br><span class="line">            logger.info(<span class="string">"node name derived from node ID [&#123;&#125;]; set [&#123;&#125;] to override"</span>, nodeId, NODE_NAME_SETTING.getKey());</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            logger.info(<span class="string">"node name [&#123;&#125;], node ID [&#123;&#125;]"</span>, nodeName, nodeId);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//2、打印出JVM相关信息</span></span><br><span class="line">        <span class="keyword">final</span> JvmInfo jvmInfo = JvmInfo.jvmInfo();</span><br><span class="line">        logger.info(</span><br><span class="line"><span class="string">"version[&#123;&#125;], pid[&#123;&#125;], build[&#123;&#125;/&#123;&#125;/&#123;&#125;/&#123;&#125;], OS[&#123;&#125;/&#123;&#125;/&#123;&#125;], JVM[&#123;&#125;/&#123;&#125;/&#123;&#125;/&#123;&#125;]"</span>,</span><br><span class="line">            Version.displayVersion(Version.CURRENT, Build.CURRENT.isSnapshot()),</span><br><span class="line">            jvmInfo.pid(), Build.CURRENT.flavor().displayName(),</span><br><span class="line">            Build.CURRENT.type().displayName(), Build.CURRENT.shortHash(),</span><br><span class="line">            Build.CURRENT.date(), Constants.OS_NAME, Constants.OS_VERSION,</span><br><span class="line">            Constants.OS_ARCH,Constants.JVM_VENDOR,Constants.JVM_NAME,</span><br><span class="line">            Constants.JAVA_VERSION,Constants.JVM_VERSION);</span><br><span class="line">        logger.info(<span class="string">"JVM arguments &#123;&#125;"</span>, Arrays.toString(jvmInfo.getInputArguments()));</span><br><span class="line">        <span class="comment">//检查当前版本是不是 pre-release 版本（Snapshot），</span></span><br><span class="line">        warnIfPreRelease(Version.CURRENT, Build.CURRENT.isSnapshot(), logger);</span><br><span class="line">		。。。</span><br><span class="line">        <span class="keyword">this</span>.pluginsService = <span class="keyword">new</span> PluginsService(tmpSettings, environment.configFile(), environment.modulesFile(), environment.pluginsFile(), classpathPlugins);   <span class="comment">//3、利用PluginsService加载相应的模块和插件</span></span><br><span class="line">        <span class="keyword">this</span>.settings = pluginsService.updatedSettings();</span><br><span class="line">        localNodeFactory = <span class="keyword">new</span> LocalNodeFactory(settings, nodeEnvironment.nodeId());</span><br><span class="line"></span><br><span class="line"><span class="comment">// create the environment based on the finalized (processed) view of the settings</span></span><br><span class="line"><span class="comment">// this is just to makes sure that people get the same settings, no matter where they ask them from</span></span><br><span class="line">        <span class="keyword">this</span>.environment = <span class="keyword">new</span> Environment(<span class="keyword">this</span>.settings, environment.configFile());</span><br><span class="line">        Environment.assertEquivalent(environment, <span class="keyword">this</span>.environment);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> List&lt;ExecutorBuilder&lt;?&gt;&gt; executorBuilders = pluginsService.getExecutorBuilders(settings);        <span class="comment">//线程池</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> ThreadPool threadPool = <span class="keyword">new</span> ThreadPool(settings, executorBuilders.toArray(<span class="keyword">new</span> ExecutorBuilder[<span class="number">0</span>]));</span><br><span class="line">        resourcesToClose.add(() -&gt; ThreadPool.terminate(threadPool, <span class="number">10</span>, TimeUnit.SECONDS));</span><br><span class="line">        <span class="comment">// adds the context to the DeprecationLogger so that it does not need to be injected everywhere</span></span><br><span class="line">        DeprecationLogger.setThreadContext(threadPool.getThreadContext());</span><br><span class="line">        resourcesToClose.add(() -&gt; DeprecationLogger.removeThreadContext(threadPool.getThreadContext()));</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> List&lt;Setting&lt;?&gt;&gt; additionalSettings = <span class="keyword">new</span> ArrayList&lt;&gt;(pluginsService.getPluginSettings());       <span class="comment">//额外配置</span></span><br><span class="line">        <span class="keyword">final</span> List&lt;String&gt; additionalSettingsFilter = <span class="keyword">new</span> ArrayList&lt;&gt;(pluginsService.getPluginSettingsFilter());</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">final</span> ExecutorBuilder&lt;?&gt; builder : threadPool.builders()) &#123;</span><br><span class="line">            <span class="comment">//4、加载一些额外配置</span></span><br><span class="line">            additionalSettings.addAll(builder.getRegisteredSettings());</span><br><span class="line">        &#125;</span><br><span class="line">        client = <span class="keyword">new</span> NodeClient(settings, threadPool);<span class="comment">//5、创建一个节点客户端                                                                                  </span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//6、缓存一系列模块,如NodeModule,ClusterModule,IndicesModule,ActionModule,GatewayModule,SettingsModule,RepositioriesModule，scriptModule，analysisModule</span></span><br><span class="line">        <span class="keyword">final</span> ResourceWatcherService resourceWatcherService = <span class="keyword">new</span> ResourceWatcherService(settings, threadPool);</span><br><span class="line">        <span class="keyword">final</span> ScriptModule scriptModule = <span class="keyword">new</span> ScriptModule(settings, pluginsService.filterPlugins(ScriptPlugin.class));</span><br><span class="line">        AnalysisModule analysisModule = <span class="keyword">new</span> AnalysisModule(<span class="keyword">this</span>.environment, pluginsService.filterPlugins(AnalysisPlugin.class));</span><br><span class="line">        <span class="comment">// this is as early as we can validate settings at this point. we already pass them to ScriptModule as well as ThreadPool so we might be late here already</span></span><br><span class="line">        <span class="keyword">final</span> SettingsModule settingsModule = <span class="keyword">new</span> SettingsModule(<span class="keyword">this</span>.settings, additionalSettings, additionalSettingsFilter);</span><br><span class="line">scriptModule.registerClusterSettingsListeners(settingsModule.getClusterSettings());</span><br><span class="line">        resourcesToClose.add(resourceWatcherService);</span><br><span class="line">        <span class="keyword">final</span> NetworkService networkService = <span class="keyword">new</span> NetworkService(</span><br><span class="line">  getCustomNameResolvers(pluginsService.filterPlugins(DiscoveryPlugin.class)));</span><br><span class="line">        List&lt;ClusterPlugin&gt; clusterPlugins = pluginsService.filterPlugins(ClusterPlugin.class);</span><br><span class="line">        <span class="keyword">final</span> ClusterService clusterService = <span class="keyword">new</span> ClusterService(settings, settingsModule.getClusterSettings(), threadPool,                                                      ClusterModule.getClusterStateCustomSuppliers(clusterPlugins));</span><br><span class="line">        clusterService.addStateApplier(scriptModule.getScriptService());</span><br><span class="line">        resourcesToClose.add(clusterService);</span><br><span class="line">        <span class="keyword">final</span> IngestService ingestService = <span class="keyword">new</span> IngestService(settings, threadPool, <span class="keyword">this</span>.environment,                                                  scriptModule.getScriptService(), analysisModule.getAnalysisRegistry(), pluginsService.filterPlugins(IngestPlugin.class));</span><br><span class="line">        <span class="keyword">final</span> DiskThresholdMonitor listener = <span class="keyword">new</span> DiskThresholdMonitor(settings, clusterService::state, clusterService.getClusterSettings(), client);</span><br><span class="line">        <span class="keyword">final</span> ClusterInfoService clusterInfoService = newClusterInfoService(settings, clusterService, threadPool, client,</span><br><span class="line">listener::onNewInfo);</span><br><span class="line">        <span class="keyword">final</span> UsageService usageService = <span class="keyword">new</span> UsageService(settings);</span><br><span class="line"></span><br><span class="line">        ModulesBuilder modules = <span class="keyword">new</span> ModulesBuilder();</span><br><span class="line"><span class="comment">// plugin modules must be added here, before others or we can get crazy injection errors...</span></span><br><span class="line">        <span class="keyword">for</span> (Module pluginModule : pluginsService.createGuiceModules()) &#123;</span><br><span class="line">            modules.add(pluginModule);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">final</span> MonitorService monitorService = <span class="keyword">new</span> MonitorService(settings, nodeEnvironment, threadPool, clusterInfoService);</span><br><span class="line">        ClusterModule clusterModule = <span class="keyword">new</span> ClusterModule(settings, clusterService, clusterPlugins, clusterInfoService);</span><br><span class="line">        modules.add(clusterModule);</span><br><span class="line">        IndicesModule indicesModule = <span class="keyword">new</span> IndicesModule(pluginsService.filterPlugins(MapperPlugin.class));</span><br><span class="line">        modules.add(indicesModule);</span><br><span class="line"></span><br><span class="line">        SearchModule searchModule = <span class="keyword">new</span> SearchModule(settings, <span class="keyword">false</span>, pluginsService.filterPlugins(SearchPlugin.class));</span><br><span class="line">        CircuitBreakerService circuitBreakerService = createCircuitBreakerService(settingsModule.getSettings(),</span><br><span class="line">                                                                                  settingsModule.getClusterSettings());</span><br><span class="line">        resourcesToClose.add(circuitBreakerService);</span><br><span class="line">        modules.add(<span class="keyword">new</span> GatewayModule());</span><br><span class="line"></span><br><span class="line">        PageCacheRecycler pageCacheRecycler = createPageCacheRecycler(settings);</span><br><span class="line">        BigArrays bigArrays = createBigArrays(pageCacheRecycler, circuitBreakerService);</span><br><span class="line">        resourcesToClose.add(bigArrays);</span><br><span class="line">        modules.add(settingsModule);</span><br><span class="line">        List&lt;NamedWriteableRegistry.Entry&gt; namedWriteables = Stream.of(</span><br><span class="line">            NetworkModule.getNamedWriteables().stream(),</span><br><span class="line">            indicesModule.getNamedWriteables().stream(),</span><br><span class="line">            searchModule.getNamedWriteables().stream(),</span><br><span class="line">            pluginsService.filterPlugins(Plugin.class).stream()</span><br><span class="line">            .flatMap(p -&gt; p.getNamedWriteables().stream()),</span><br><span class="line">            ClusterModule.getNamedWriteables().stream())</span><br><span class="line">            .flatMap(Function.identity()).collect(Collectors.toList());</span><br><span class="line">        <span class="keyword">final</span> NamedWriteableRegistry namedWriteableRegistry = <span class="keyword">new</span> NamedWriteableRegistry(namedWriteables);</span><br><span class="line">        NamedXContentRegistry xContentRegistry = <span class="keyword">new</span> NamedXContentRegistry(Stream.of(</span><br><span class="line">            NetworkModule.getNamedXContents().stream(),</span><br><span class="line">            searchModule.getNamedXContents().stream(),</span><br><span class="line">            pluginsService.filterPlugins(Plugin.class).stream()</span><br><span class="line">            .flatMap(p -&gt; p.getNamedXContent().stream()),</span><br><span class="line">            ClusterModule.getNamedXWriteables().stream())</span><br><span class="line">.flatMap(Function.identity()).collect(toList()));</span><br><span class="line">        modules.add(<span class="keyword">new</span> RepositoriesModule(<span class="keyword">this</span>.environment, pluginsService.filterPlugins(RepositoryPlugin.class), xContentRegistry));</span><br><span class="line">        <span class="keyword">final</span> MetaStateService metaStateService = <span class="keyword">new</span> MetaStateService(settings, nodeEnvironment, xContentRegistry);</span><br><span class="line">        <span class="keyword">final</span> IndicesService indicesService = <span class="keyword">new</span> IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry,</span><br><span class="line">analysisModule.getAnalysisRegistry(),                                                                clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,threadPool, settingsModule.getIndexScopedSettings(), circuitBreakerService, bigArrays, scriptModule.getScriptService(),client, metaStateService);</span><br><span class="line"></span><br><span class="line">        Collection&lt;Object&gt; pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()</span><br><span class="line">            .flatMap(p -&gt; p.createComponents(client, clusterService, threadPool, resourceWatcherService,scriptModule.getScriptService(), xContentRegistry, environment, nodeEnvironment,namedWriteableRegistry).stream())</span><br><span class="line">.collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line">        ActionModule actionModule = <span class="keyword">new</span> ActionModule(<span class="keyword">false</span>, settings, clusterModule.getIndexNameExpressionResolver(),</span><br><span class="line">                                                     settingsModule.getIndexScopedSettings(), settingsModule.getClusterSettings(), settingsModule.getSettingsFilter(),threadPool, pluginsService.filterPlugins(ActionPlugin.class), client, circuitBreakerService, usageService);</span><br><span class="line">        modules.add(actionModule);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//7、获取RestController,用于处理各种Elasticsearch的rest命令,如_cat,_all,_cat/health,_clusters等rest命令(Elasticsearch称之为action)</span></span><br><span class="line">        <span class="keyword">final</span> RestController restController = actionModule.getRestController();</span><br><span class="line">        <span class="keyword">final</span> NetworkModule networkModule = <span class="keyword">new</span> NetworkModule(settings, <span class="keyword">false</span>, pluginsService.filterPlugins(NetworkPlugin.class),threadPool, bigArrays, pageCacheRecycler, circuitBreakerService, namedWriteableRegistry, xContentRegistry,networkService, restController);</span><br><span class="line">        Collection&lt;UnaryOperator&lt;Map&lt;String, MetaData.Custom&gt;&gt;&gt; customMetaDataUpgraders =</span><br><span class="line">            pluginsService.filterPlugins(Plugin.class).stream()</span><br><span class="line">            .map(Plugin::getCustomMetaDataUpgrader)</span><br><span class="line">            .collect(Collectors.toList());</span><br><span class="line">        Collection&lt;UnaryOperator&lt;Map&lt;String, IndexTemplateMetaData&gt;&gt;&gt; indexTemplateMetaDataUpgraders =</span><br><span class="line">            pluginsService.filterPlugins(Plugin.class).stream()</span><br><span class="line">            .map(Plugin::getIndexTemplateMetaDataUpgrader)</span><br><span class="line">            .collect(Collectors.toList());</span><br><span class="line">        Collection&lt;UnaryOperator&lt;IndexMetaData&gt;&gt; indexMetaDataUpgraders = pluginsService.filterPlugins(Plugin.class).stream()</span><br><span class="line">            .map(Plugin::getIndexMetaDataUpgrader).collect(Collectors.toList());</span><br><span class="line">        <span class="keyword">final</span> MetaDataUpgrader metaDataUpgrader = <span class="keyword">new</span> MetaDataUpgrader(customMetaDataUpgraders, indexTemplateMetaDataUpgraders);</span><br><span class="line">        <span class="keyword">final</span> MetaDataIndexUpgradeService metaDataIndexUpgradeService = <span class="keyword">new</span> MetaDataIndexUpgradeService(settings, xContentRegistry,                                                                                            indicesModule.getMapperRegistry(), settingsModule.getIndexScopedSettings(), indexMetaDataUpgraders);</span><br><span class="line">        <span class="keyword">final</span> GatewayMetaState gatewayMetaState = <span class="keyword">new</span> GatewayMetaState(settings, nodeEnvironment, metaStateService,                                                      metaDataIndexUpgradeService, metaDataUpgrader);</span><br><span class="line">        <span class="keyword">new</span> TemplateUpgradeService(settings, client, clusterService, threadPool, indexTemplateMetaDataUpgraders);</span><br><span class="line">        <span class="keyword">final</span> Transport transport = networkModule.getTransportSupplier().get();</span><br><span class="line">        Set&lt;String&gt; taskHeaders = Stream.concat(</span><br><span class="line">            pluginsService.filterPlugins(ActionPlugin.class).stream().flatMap(p -&gt; p.getTaskHeaders().stream()),</span><br><span class="line">            Stream.of(<span class="string">"X-Opaque-Id"</span>)</span><br><span class="line">        ).collect(Collectors.toSet());</span><br><span class="line">        <span class="keyword">final</span> TransportService transportService = newTransportService(settings, transport, threadPool,</span><br><span class="line">                                                                      networkModule.getTransportInterceptor(), localNodeFactory, settingsModule.getClusterSettings(), taskHeaders);</span><br><span class="line">        <span class="keyword">final</span> ResponseCollectorService responseCollectorService = <span class="keyword">new</span> ResponseCollectorService(<span class="keyword">this</span>.settings, clusterService);</span><br><span class="line">        <span class="keyword">final</span> SearchTransportService searchTransportService =  <span class="keyword">new</span> SearchTransportService(settings, transportService,</span><br><span class="line">                                                                                          SearchExecutionStatsCollector.makeWrapper(responseCollectorService));</span><br><span class="line">        <span class="keyword">final</span> Consumer&lt;Binder&gt; httpBind;</span><br><span class="line">        <span class="keyword">final</span> HttpServerTransport httpServerTransport;</span><br><span class="line">        <span class="keyword">if</span> (networkModule.isHttpEnabled()) &#123;</span><br><span class="line">            httpServerTransport = networkModule.getHttpServerTransportSupplier().get();</span><br><span class="line">            httpBind = b -&gt; &#123;</span><br><span class="line">b.bind(HttpServerTransport.class).toInstance(httpServerTransport);</span><br><span class="line">            &#125;;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            httpBind = b -&gt; &#123;</span><br><span class="line">                b.bind(HttpServerTransport.class).toProvider(Providers.of(<span class="keyword">null</span>));</span><br><span class="line">            &#125;;</span><br><span class="line">            httpServerTransport = <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> DiscoveryModule discoveryModule = <span class="keyword">new</span> DiscoveryModule(<span class="keyword">this</span>.settings, threadPool, transportService, namedWriteableRegistry,networkService, clusterService.getMasterService(), clusterService.getClusterApplierService(),clusterService.getClusterSettings(), pluginsService.filterPlugins(DiscoveryPlugin.class),clusterModule.getAllocationService());</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">this</span>.nodeService = <span class="keyword">new</span> NodeService(settings, threadPool, monitorService, discoveryModule.getDiscovery(),transportService, indicesService, pluginsService, circuitBreakerService, scriptModule.getScriptService(),httpServerTransport, ingestService, clusterService, settingsModule.getSettingsFilter(), responseCollectorService,searchTransportService);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> SearchService searchService = newSearchService(clusterService, indicesService, threadPool, scriptModule.getScriptService(), bigArrays, searchModule.getFetchPhase(),responseCollectorService);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> List&lt;PersistentTasksExecutor&lt;?&gt;&gt; tasksExecutors = pluginsService</span><br><span class="line">            .filterPlugins(PersistentTaskPlugin.class).stream()</span><br><span class="line">     .map(p -&gt; p.getPersistentTasksExecutor(clusterService, threadPool, client))</span><br><span class="line">            .flatMap(List::stream)</span><br><span class="line">            .collect(toList());</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> PersistentTasksExecutorRegistry registry = <span class="keyword">new</span> PersistentTasksExecutorRegistry(settings, tasksExecutors);</span><br><span class="line">        <span class="keyword">final</span> PersistentTasksClusterService persistentTasksClusterService =</span><br><span class="line">            <span class="keyword">new</span> PersistentTasksClusterService(settings, registry, clusterService);</span><br><span class="line">        <span class="keyword">final</span> PersistentTasksService persistentTasksService = <span class="keyword">new</span> PersistentTasksService(settings, clusterService, threadPool, client);</span><br><span class="line"></span><br><span class="line"><span class="comment">//8、绑定处理各种服务的实例,这里是最核心的地方,也是Elasticsearch能处理各种服务的核心.</span></span><br><span class="line">        modules.add(b -&gt; &#123;</span><br><span class="line">            b.bind(Node.class).toInstance(<span class="keyword">this</span>);</span><br><span class="line">            b.bind(NodeService.class).toInstance(nodeService);</span><br><span class="line">            b.bind(NamedXContentRegistry.class).toInstance(xContentRegistry);</span><br><span class="line">            b.bind(PluginsService.class).toInstance(pluginsService);</span><br><span class="line">            b.bind(Client.class).toInstance(client);</span><br><span class="line">            b.bind(NodeClient.class).toInstance(client);</span><br><span class="line">            b.bind(Environment.class).toInstance(<span class="keyword">this</span>.environment);</span><br><span class="line">            b.bind(ThreadPool.class).toInstance(threadPool);</span><br><span class="line">            b.bind(NodeEnvironment.class).toInstance(nodeEnvironment);</span><br><span class="line"> b.bind(ResourceWatcherService.class).toInstance(resourceWatcherService);</span><br><span class="line">b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService);</span><br><span class="line">            b.bind(BigArrays.class).toInstance(bigArrays);</span><br><span class="line">      b.bind(ScriptService.class).toInstance(scriptModule.getScriptService());</span><br><span class="line"> b.bind(AnalysisRegistry.class).toInstance(analysisModule.getAnalysisRegistry());</span><br><span class="line">            b.bind(IngestService.class).toInstance(ingestService);</span><br><span class="line">            b.bind(UsageService.class).toInstance(usageService);</span><br><span class="line"> b.bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);</span><br><span class="line">            b.bind(MetaDataUpgrader.class).toInstance(metaDataUpgrader);</span><br><span class="line">            b.bind(MetaStateService.class).toInstance(metaStateService);</span><br><span class="line">            b.bind(IndicesService.class).toInstance(indicesService);</span><br><span class="line">            b.bind(SearchService.class).toInstance(searchService);            b.bind(SearchTransportService.class).toInstance(searchTransportService);</span><br><span class="line">b.bind(SearchPhaseController.class).toInstance(<span class="keyword">new</span> SearchPhaseController(settings, searchService::createReduceContext));</span><br><span class="line">            b.bind(Transport.class).toInstance(transport);</span><br><span class="line">            b.bind(TransportService.class).toInstance(transportService);</span><br><span class="line">            b.bind(NetworkService.class).toInstance(networkService);</span><br><span class="line">            b.bind(UpdateHelper.class).toInstance(<span class="keyword">new</span> UpdateHelper(settings, scriptModule.getScriptService()));</span><br><span class="line">b.bind(MetaDataIndexUpgradeService.class).toInstance(metaDataIndexUpgradeService);</span><br><span class="line">            b.bind(ClusterInfoService.class).toInstance(clusterInfoService);</span><br><span class="line">            b.bind(GatewayMetaState.class).toInstance(gatewayMetaState);</span><br><span class="line">            b.bind(Discovery.class).toInstance(discoveryModule.getDiscovery());</span><br><span class="line">            &#123;</span><br><span class="line">                RecoverySettings recoverySettings = <span class="keyword">new</span> RecoverySettings(settings, settingsModule.getClusterSettings());</span><br><span class="line">                processRecoverySettings(settingsModule.getClusterSettings(), recoverySettings);</span><br><span class="line">                b.bind(PeerRecoverySourceService.class).toInstance(<span class="keyword">new</span> PeerRecoverySourceService(settings, transportService,</span><br><span class="line">indicesService, recoverySettings));</span><br><span class="line">                b.bind(PeerRecoveryTargetService.class).toInstance(<span class="keyword">new</span> PeerRecoveryTargetService(settings, threadPool,</span><br><span class="line">transportService, recoverySettings, clusterService));</span><br><span class="line">            &#125;</span><br><span class="line">            httpBind.accept(b);</span><br><span class="line">            pluginComponents.stream().forEach(p -&gt; b.bind((Class) p.getClass()).toInstance(p));</span><br><span class="line">b.bind(PersistentTasksService.class).toInstance(persistentTasksService);       b.bind(PersistentTasksClusterService.class).toInstance(persistentTasksClusterService);</span><br><span class="line">b.bind(PersistentTasksExecutorRegistry.class).toInstance(registry); &#125;);</span><br><span class="line">        injector = modules.createInjector();</span><br><span class="line"></span><br><span class="line">        <span class="comment">// TODO hack around circular dependencies problems in AllocationService</span></span><br><span class="line">clusterModule.getAllocationService().setGatewayAllocator(injector.getInstance(GatewayAllocator.class));</span><br><span class="line"></span><br><span class="line">        List&lt;LifecycleComponent&gt; pluginLifecycleComponents = pluginComponents.stream()</span><br><span class="line">            .filter(p -&gt; p <span class="keyword">instanceof</span> LifecycleComponent)</span><br><span class="line">            .map(p -&gt; (LifecycleComponent) p).collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line">        <span class="comment">//9、利用Guice将各种模块以及服务(xxxService)注入到Elasticsearch环境中</span></span><br><span class="line">pluginLifecycleComponents.addAll(pluginsService.getGuiceServiceClasses().stream()                                     .map(injector::getInstance).collect(Collectors.toList()));</span><br><span class="line">        resourcesToClose.addAll(pluginLifecycleComponents);</span><br><span class="line">        <span class="keyword">this</span>.pluginLifecycleComponents = Collections.unmodifiableList(pluginLifecycleComponents);</span><br><span class="line">        client.initialize(injector.getInstance(<span class="keyword">new</span> Key&lt;Map&lt;GenericAction, TransportAction&gt;&gt;() &#123;&#125;), () -&gt; clusterService.localNode().getId(), transportService.getRemoteClusterService());</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (NetworkModule.HTTP_ENABLED.get(settings)) &#123; <span class="comment">//如果elasticsearch.yml文件中配置了http.enabled参数(默认为true),则会初始化RestHandlers</span></span><br><span class="line">            logger.debug(<span class="string">"initializing HTTP handlers ..."</span>);</span><br><span class="line">            actionModule.initRestHandlers(() -&gt; clusterService.state().nodes()); <span class="comment">//初始化RestHandlers, 解析集群命令,如_cat/,_cat/health</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//10、初始化工作完成</span></span><br><span class="line">        logger.info(<span class="string">"initialized"</span>);</span><br><span class="line"></span><br><span class="line">        success = <span class="keyword">true</span>;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (IOException ex) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> ElasticsearchException(<span class="string">"failed to bind service"</span>, ex);</span><br><span class="line">    &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (!success) &#123;</span><br><span class="line">            IOUtils.closeWhileHandlingException(resourcesToClose);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上面代码真的很多，这里再说下上面这么多代码主要干了什么吧：（具体是哪行代码执行的如下流程，上面代码中也标记了）</p>
<p>1、创建节点环境,比如节点名称,节点 ID,分片信息,存储元,以及分配内存准备给节点使用</p>
<p>2、打印出 JVM 相关信息</p>
<p>3、利用 PluginsService 加载相应的模块和插件，具体哪些模块可以去 modules 目录下查看</p>
<p>4、加载一些额外的配置参数</p>
<p>5、创建一个节点客户端</p>
<p>6、缓存一系列模块,如NodeModule,ClusterModule,IndicesModule,ActionModule,GatewayModule,SettingsModule,RepositioriesModule，scriptModule，analysisModule</p>
<p>7、获取 RestController，用于处理各种 Elasticsearch 的 rest 命令,如 _cat, _all, _cat/health, _clusters 等 rest命令</p>
<p>8、绑定处理各种服务的实例</p>
<p>9、利用 Guice 将各种模块以及服务(xxxService)注入到 Elasticsearch 环境中</p>
<p>10、初始化工作完成（打印日志）</p>
<h3 id="JarHell-报错解释"><a href="#JarHell-报错解释" class="headerlink" title="JarHell 报错解释"></a>JarHell 报错解释</h3><p>前一篇阅读源码环境搭建的文章写过用 JDK 1.8 编译 ES 源码是会遇到如下异常：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: jar hell!</span><br></pre></td></tr></table></figure>
<p>这里说下就是 setup 方法中的如下代码导致的</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="comment">// look for jar hell</span></span><br><span class="line">    <span class="keyword">final</span> Logger logger = ESLoggerFactory.getLogger(JarHell.class);</span><br><span class="line">    JarHell.checkJarHell(logger::debug);</span><br><span class="line">&#125; <span class="keyword">catch</span> (IOException | URISyntaxException e) &#123;</span><br><span class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> BootstrapException(e);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>所以你如果是用 JDK 1.8 编译的，那么就需要把所有的有这块的代码给注释掉就可以编译成功的。</p>
<p>我自己试过用 JDK 10 编译是没有出现这里报错的。</p>
<h3 id="正式启动-ES-节点"><a href="#正式启动-ES-节点" class="headerlink" title="正式启动 ES 节点"></a>正式启动 ES 节点</h3><p>回到上面 Bootstrap 中的静态 init 方法中，接下来就是正式启动 elasticsearch 节点了：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">INSTANCE.start();  <span class="comment">//调用下面的 start 方法</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">start</span><span class="params">()</span> <span class="keyword">throws</span> NodeValidationException </span>&#123;</span><br><span class="line">    node.start();                                       <span class="comment">//正式启动 Elasticsearch 节点</span></span><br><span class="line">    keepAliveThread.start();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>接下来看看这个 start 方法里面的 <code>node.start()</code> 方法源码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> Node <span class="title">start</span><span class="params">()</span> <span class="keyword">throws</span> NodeValidationException </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!lifecycle.moveToStarted()) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings));</span><br><span class="line">    logger.info(<span class="string">"starting ..."</span>);</span><br><span class="line">    pluginLifecycleComponents.forEach(LifecycleComponent::start); </span><br><span class="line">    </span><br><span class="line">    <span class="comment">//1、利用Guice获取上述注册的各种模块以及服务</span></span><br><span class="line">    <span class="comment">//Node 的启动其实就是 node 里每个组件的启动，同样的，分别调用不同的实例的 start 方法来启动这个组件, 如下：</span></span><br><span class="line">    injector.getInstance(MappingUpdatedAction.class).setClient(client);</span><br><span class="line">    injector.getInstance(IndicesService.class).start();</span><br><span class="line">    injector.getInstance(IndicesClusterStateService.class).start();</span><br><span class="line">    injector.getInstance(SnapshotsService.class).start();</span><br><span class="line">    injector.getInstance(SnapshotShardsService.class).start();</span><br><span class="line">    injector.getInstance(RoutingService.class).start();</span><br><span class="line">    injector.getInstance(SearchService.class).start();</span><br><span class="line">    nodeService.getMonitorService().start();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> ClusterService clusterService = injector.getInstance(ClusterService.class);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> NodeConnectionsService nodeConnectionsService = injector.getInstance(NodeConnectionsService.class);</span><br><span class="line">    nodeConnectionsService.start();</span><br><span class="line">    clusterService.setNodeConnectionsService(nodeConnectionsService);</span><br><span class="line"></span><br><span class="line">    injector.getInstance(ResourceWatcherService.class).start();</span><br><span class="line">    injector.getInstance(GatewayService.class).start();</span><br><span class="line">    Discovery discovery = injector.getInstance(Discovery.class);</span><br><span class="line">    clusterService.getMasterService().setClusterStatePublisher(discovery::publish);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Start the transport service now so the publish address will be added to the local disco node in ClusterService</span></span><br><span class="line">    TransportService transportService = injector.getInstance(TransportService.class);</span><br><span class="line">    transportService.getTaskManager().setTaskResultsService(injector.getInstance(TaskResultsService.class));</span><br><span class="line">    transportService.start();</span><br><span class="line">    <span class="keyword">assert</span> localNodeFactory.getNode() != <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">assert</span> transportService.getLocalNode().equals(localNodeFactory.getNode())</span><br><span class="line">        : <span class="string">"transportService has a different local node than the factory provided"</span>;</span><br><span class="line">    <span class="keyword">final</span> MetaData onDiskMetadata;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">// we load the global state here (the persistent part of the cluster state stored on disk) to</span></span><br><span class="line">        <span class="comment">// pass it to the bootstrap checks to allow plugins to enforce certain preconditions based on the recovered state.</span></span><br><span class="line">        <span class="keyword">if</span> (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) &#123;<span class="comment">//根据配置文件看当前节点是master还是data节点</span></span><br><span class="line">            onDiskMetadata = injector.getInstance(GatewayMetaState.class).loadMetaState();</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            onDiskMetadata = MetaData.EMPTY_META_DATA;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">assert</span> onDiskMetadata != <span class="keyword">null</span> : <span class="string">"metadata is null but shouldn't"</span>; <span class="comment">// this is never null</span></span><br><span class="line">    &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> UncheckedIOException(e);</span><br><span class="line">    &#125;</span><br><span class="line">    validateNodeBeforeAcceptingRequests(<span class="keyword">new</span> BootstrapContext(settings, onDiskMetadata), transportService.boundAddress(), pluginsService</span><br><span class="line">        .filterPlugins(Plugin</span><br><span class="line">        .class)</span><br><span class="line">        .stream()</span><br><span class="line">        .flatMap(p -&gt; p.getBootstrapChecks().stream()).collect(Collectors.toList()));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//2、将当前节点加入到一个集群簇中去,并启动当前节点</span></span><br><span class="line">    clusterService.addStateApplier(transportService.getTaskManager());</span><br><span class="line">    <span class="comment">// start after transport service so the local disco is known</span></span><br><span class="line">    discovery.start(); <span class="comment">// start before cluster service so that it can set initial state on ClusterApplierService</span></span><br><span class="line">    clusterService.start();</span><br><span class="line">    <span class="keyword">assert</span> clusterService.localNode().equals(localNodeFactory.getNode())</span><br><span class="line">        : <span class="string">"clusterService has a different local node than the factory provided"</span>;</span><br><span class="line">    transportService.acceptIncomingRequests();</span><br><span class="line">    discovery.startInitialJoin();</span><br><span class="line">    <span class="comment">// tribe nodes don't have a master so we shouldn't register an observer         s</span></span><br><span class="line">    <span class="keyword">final</span> TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings);</span><br><span class="line">    <span class="keyword">if</span> (initialStateTimeout.millis() &gt; <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="keyword">final</span> ThreadPool thread = injector.getInstance(ThreadPool.class);</span><br><span class="line">        ClusterState clusterState = clusterService.state();</span><br><span class="line">        ClusterStateObserver observer = <span class="keyword">new</span> ClusterStateObserver(clusterState, clusterService, <span class="keyword">null</span>, logger, thread.getThreadContext());</span><br><span class="line">        <span class="keyword">if</span> (clusterState.nodes().getMasterNodeId() == <span class="keyword">null</span>) &#123;</span><br><span class="line">            logger.debug(<span class="string">"waiting to join the cluster. timeout [&#123;&#125;]"</span>, initialStateTimeout);</span><br><span class="line">            <span class="keyword">final</span> CountDownLatch latch = <span class="keyword">new</span> CountDownLatch(<span class="number">1</span>);</span><br><span class="line">            observer.waitForNextChange(<span class="keyword">new</span> ClusterStateObserver.Listener() &#123;</span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onNewClusterState</span><span class="params">(ClusterState state)</span> </span>&#123; latch.countDown(); &#125;</span><br><span class="line"></span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClusterServiceClose</span><span class="params">()</span> </span>&#123;</span><br><span class="line">                    latch.countDown();</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onTimeout</span><span class="params">(TimeValue timeout)</span> </span>&#123;</span><br><span class="line">                    logger.warn(<span class="string">"timed out while waiting for initial discovery state - timeout: &#123;&#125;"</span>,</span><br><span class="line">                        initialStateTimeout);</span><br><span class="line">                    latch.countDown();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;, state -&gt; state.nodes().getMasterNodeId() != <span class="keyword">null</span>, initialStateTimeout);</span><br><span class="line"></span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                latch.await();</span><br><span class="line">            &#125; <span class="keyword">catch</span> (InterruptedException e) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> ElasticsearchTimeoutException(<span class="string">"Interrupted while waiting for initial discovery state"</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (NetworkModule.HTTP_ENABLED.get(settings)) &#123;</span><br><span class="line">        injector.getInstance(HttpServerTransport.class).start();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (WRITE_PORTS_FILE_SETTING.get(settings)) &#123;</span><br><span class="line">        <span class="keyword">if</span> (NetworkModule.HTTP_ENABLED.get(settings)) &#123;</span><br><span class="line">            HttpServerTransport http = injector.getInstance(HttpServerTransport.class);</span><br><span class="line">            writePortsFile(<span class="string">"http"</span>, http.boundAddress());</span><br><span class="line">        &#125;</span><br><span class="line">        TransportService transport = injector.getInstance(TransportService.class);</span><br><span class="line">        writePortsFile(<span class="string">"transport"</span>, transport.boundAddress());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    logger.info(<span class="string">"started"</span>);</span><br><span class="line"></span><br><span class="line">    pluginsService.filterPlugins(ClusterPlugin.class).forEach(ClusterPlugin::onNodeStarted);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上面代码主要是：</p>
<p>1、利用 Guice 获取上述注册的各种模块以及服务，然后启动 node 里每个组件（分别调用不同的实例的 start 方法来启动）</p>
<p>2、打印日志（启动节点完成）</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>这篇文章主要把大概启动流程串通了，讲了下 node 节点的创建和正式启动 ES 节点了。因为篇幅较多所以拆开成两篇，先不扣细节了，后面流程启动文章写完后我们再单一的扣细节。</p>
<h3 id="相关文章"><a href="#相关文章" class="headerlink" title="相关文章"></a>相关文章</h3><p>1、<a href="http://www.54tianzhisheng.cn/2018/08/04/why-see-es-code/">渣渣菜鸡为什么要看 ElasticSearch 源码？</a></p>
<p>2、<a href="http://www.54tianzhisheng.cn/2018/08/05/es-code01/">渣渣菜鸡的 ElasticSearch 源码解析 —— 环境搭建</a></p>
<p>3、<a href="http://www.54tianzhisheng.cn/2018/08/11/es-code02/">渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程(上)</a></p>
<p>4、<a href="http://www.54tianzhisheng.cn/2018/08/11/es-code03/">渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程(下)</a></p>
<p>5、<a href="http://www.54tianzhisheng.cn/2017/09/08/Elasticsearch-analyzers/">Elasticsearch 系列文章（一）：Elasticsearch 默认分词器和中分分词器之间的比较及使用方法</a></p>
<p>6、<a href="http://www.54tianzhisheng.cn/2017/09/09/Elasticsearch-install/">Elasticsearch 系列文章（二）：全文搜索引擎 Elasticsearch 集群搭建入门教程</a></p>
<p>7、<a href="http://www.54tianzhisheng.cn/2017/10/15/ElasticSearch-cluster-health-metrics/">Elasticsearch 系列文章（三）：ElasticSearch 集群监控</a></p>
<p>8、<a href="http://www.54tianzhisheng.cn/2017/10/18/ElasticSearch-nodes-metrics/">Elasticsearch 系列文章（四）：ElasticSearch 单个节点监控</a></p>
<p>9、<a href="http://www.54tianzhisheng.cn/2017/12/25/ELK/">Elasticsearch 系列文章（五）：ELK 实时日志分析平台环境搭建</a></p>
<p>10、<a href="http://www.54tianzhisheng.cn/2018/08/14/idea-remote-debug-elasticsearch/">教你如何在 IDEA 远程 Debug ElasticSearch</a></p>

      
      
        <div class="page-reward">
          <p><a href="javascript:void(0)" onclick="dashangToggle()" class="dashang">赏</a></p>
          <div class="hide_box"></div>
          <div class="shang_box">
            <a class="shang_close" href="javascript:void(0)" onclick="dashangToggle()">×</a>
            <div class="shang_tit">
              <p>纯属好玩</p>
            </div>
            <div class="shang_payimg">
              <img src="/img/alipayimg.jpg" alt="扫码支持" title="扫一扫" />
            </div>
              <div class="pay_explain">扫码打赏，你说多少就多少</div>
            <div class="shang_payselect">
              
                <div class="pay_item checked" data-id="alipay">
                  <span class="radiobox"></span>
                  <span class="pay_logo"><img src="/img/alipay.png" alt="支付宝" /></span>
                </div>
              
              
                <div class="pay_item" data-id="wechat">
                  <span class="radiobox"></span>
                  <span class="pay_logo"><img src="/img/weixin.png" alt="微信" /></span>
                </div>
              
            </div>
            <div class="shang_info">
              <p>打开<span id="shang_pay_txt">支付宝</span>扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
        </div>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
        <script type="text/javascript">
          $(".pay_item").click(function(){
            $(this).addClass('checked').siblings('.pay_item').removeClass('checked');
            var dataid=$(this).attr('data-id');
            $(".shang_payimg img").attr("src","/img/"+dataid+"img.jpg");
            $("#shang_pay_txt").text(dataid=="alipay"?"支付宝":"微信");
          });
          function dashangToggle(){
            
            $(".hide_box").fadeToggle();
            $(".shang_box").fadeToggle();
          }
        </script>
      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>本文标题:</span><a href="/2018/08/12/es-code03/">渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下）</a></p>
        <p><span>文章作者:</span><a href="/" title="访问 zhisheng 的个人博客">zhisheng</a></p>
        <p><span>发布时间:</span>2018年08月12日 - 00时00分</p>
        <p><span>最后更新:</span>2018年11月22日 - 22时51分</p>
        <p>
            <span>原始链接:</span><a class="post-url" href="/2018/08/12/es-code03/" title="渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下）">http://www.54tianzhisheng.cn/2018/08/12/es-code03/</a>
            <span class="copy-path" data-clipboard-text="原文: http://www.54tianzhisheng.cn/2018/08/12/es-code03/　　作者: zhisheng" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span>
            <script src="/js/clipboard.min.js"></script>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" title="中国大陆 (CC BY-NC-SA 3.0 CN)" target = "_blank">"署名-非商用-相同方式共享 3.0"</a> 转载请保留原文链接及作者。
        </p>
    </div>



<nav id="article-nav">
  
    <a href="/2018/08/14/idea-remote-debug-elasticsearch/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><</strong>
      <div class="article-nav-title">
        
          教你如何在 IDEA 远程 Debug ElasticSearch
        
      </div>
    </a>
  
  
    <a href="/2018/08/11/es-code02/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（上）</div>
      <strong class="article-nav-caption">></strong>
    </a>
  
</nav>

  
</article>

    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#关注我"><span class="toc-number">1.</span> <span class="toc-text">关注我</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#前提"><span class="toc-number">2.</span> <span class="toc-text">前提</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Node-的创建"><span class="toc-number">3.</span> <span class="toc-text">Node 的创建</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JarHell-报错解释"><span class="toc-number">4.</span> <span class="toc-text">JarHell 报错解释</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#正式启动-ES-节点"><span class="toc-number">5.</span> <span class="toc-text">正式启动 ES 节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#总结"><span class="toc-number">6.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#相关文章"><span class="toc-number">7.</span> <span class="toc-text">相关文章</span></a></li></ol>
</div>
<input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

<script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script>
    var valueHide = "隐藏目录";
    var valueShow = "显示目录";

    if ($(".left-col").is(":hidden")) {
        $("#tocButton").attr("value", valueShow);
    }
    $("#tocButton").click(function() {
        if ($("#toc").is(":hidden")) {
            $("#tocButton").attr("value", valueHide);
            $("#toc").slideDown(320);
        }
        else {
            $("#tocButton").attr("value", valueShow);
            $("#toc").slideUp(350);
        }
    })
    if ($(".toc").length < 1) {
        $("#toc, #tocButton").hide();
    }
</script>





<div class="bdsharebuttonbox">
	<a href="#" class="fx fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
	<a href="#" class="fx fa-weixin bds_weixin" data-cmd="weixin" title="分享到微信"></a>
	<a href="#" class="fx fa-qq bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
	<a href="#" class="fx fa-facebook-official bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
	<a href="#" class="fx fa-twitter bds_twi" data-cmd="twi" title="分享到Twitter"></a>
	<a href="#" class="fx fa-linkedin bds_linkedin" data-cmd="linkedin" title="分享到linkedin"></a>
	<a href="#" class="fx fa-files-o bds_copy" data-cmd="copy" title="分享到复制网址"></a>
</div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"2","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>




    
        <div id="gitments"></div>
<script src="/js/gitment.browser.js"></script>
<script>
    var gitment = new Gitment({
      id: window.location.pathname,
      owner: 'zhisheng',
      repo: 'zhisheng17.github.io',
      oauth: {
        client_id: '',
        client_secret: '',
      },
    })
    gitment.render('gitments')
</script>
    



    <div class="scroll" id="post-nav-button">
        
            <a href="/2018/08/14/idea-remote-debug-elasticsearch/" title="上一篇: 教你如何在 IDEA 远程 Debug ElasticSearch">
                <i class="fa fa-angle-left"></i>
            </a>
        
        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>
        
            <a href="/2018/08/11/es-code02/" title="下一篇: 渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（上）">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>
    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2019/01/06/Flink-Kafka-sink/">《从0到1学习Flink》—— Flink 写入数据到 Kafka</a></li><li class="post-list-item"><a class="post-list-link" href="/2019/01/05/Flink-run/">《从0到1学习Flink》—— Flink 项目如何运行？</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/12/30/Flink-ElasticSearch-Sink/">《从0到1学习Flink》—— Flink 写入数据到 ElasticSearch</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/12/11/Flink-time/">《从0到1学习Flink》—— Flink 中几种 Time 详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/12/08/Flink-Stream-Windows/">《从0到1学习Flink》—— 介绍Flink中的Stream Windows</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/11/04/Flink-Data-transformation/">《从0到1学习Flink》—— Flink Data transformation(转换)</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/10/31/flink-create-sink/">《从0到1学习Flink》—— 如何自定义 Data Sink ？</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/10/30/flink-create-source/">《从0到1学习Flink》—— 如何自定义 Data Source ？</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/10/29/flink-sink/">《从0到1学习Flink》—— Data Sink 介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/10/28/flink-sources/">《从0到1学习Flink》—— Data Source 介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/10/27/flink-config/">《从0到1学习Flink》—— Flink 配置文件详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/10/13/flink-introduction/">《从0到1学习Flink》—— Apache Flink 介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/09/18/flink-install/">《从0到1学习Flink》—— Mac 上搭建 Flink 1.6.0 环境并构建运行简单程序入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/08/30/go-sync/">Go 并发——实现协程同步的几种方式</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/08/14/idea-remote-debug-elasticsearch/">教你如何在 IDEA 远程 Debug ElasticSearch</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/08/12/es-code03/">渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（下）</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/08/11/es-code02/">渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程（上）</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/08/05/es-code01/">渣渣菜鸡的 ElasticSearch 源码解析 —— 环境搭建</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/08/04/why-see-es-code/">渣渣菜鸡为什么要看 ElasticSearch 源码？</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/07/31/alipay02/">渣渣菜鸡的蚂蚁金服面试经历(二)</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/07/30/alipay01/">渣渣菜鸡的蚂蚁金服面试经历(一)</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/07/12/youzan/">渣渣菜鸡的有赞面试经历（一）</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/06/20/java-8-date/">20 个案例教你在 Java 8 中如何处理日期和时间?</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/06/19/SimpleDateFormat/">SimpleDateFormat 如何安全的使用？</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/05/26/paper/">苦逼的毕业论文经历</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/04/30/springboot_SpringApplication/">Spring Boot 2.0系列文章(七)：SpringApplication 深入探索</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/04/24/Distributed_lock/">分布式锁看这篇就够了</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/04/19/SpringBootApplication-annotation/">Spring Boot 2.0系列文章(六)：Spring Boot 2.0中SpringBootApplication注解详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/04/18/spring_boot2_project/">Spring Boot 2.0系列文章(五)：Spring Boot 2.0 项目源码结构预览</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/04/15/springboot2_code/">Spring Boot 2.0系列文章(四)：Spring Boot 2.0 源码阅读环境搭建</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/04/13/Spring_Boot_2.0_Configuration_Changelog/">Spring Boot 2.0系列文章(三)：Spring Boot 2.0 配置改变</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/03/27/blogs/">写这么多系列博客，怪不得找不到女朋友</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/03/06/SpringBoot2-new-features/">Spring Boot 2.0系列文章(二)：Spring Boot 2.0 新特性详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/03/06/SpringBoot2-Migration-Guide/">Spring Boot 2.0系列文章(一)：Spring Boot 2.0 迁移指南</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/03/04/springboot-vedio/">小马哥 《Java 微服务实践 - Spring Boot 系列》强烈推荐</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/03/04/springcloud-vedio/">小马哥 《Java 微服务实践 - Spring Cloud 系列》强烈推荐</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/02/28/Java-Memory-Model/">《深入理解 Java 内存模型》读书笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/02/07/SpringBoot-RocketMQ/">Spring Boot系列文章（六）：SpringBoot RocketMQ 整合使用和监控</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/02/07/rocketmq-example/">RocketMQ系列文章（三）：RocketMQ 简单的消息示例</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/02/06/RocketMQ-install/">RocketMQ系列文章（二）：RocketMQ 安装及快速入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/02/05/RocketMQ/">RocketMQ系列文章（一）：RocketMQ 初探</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/28/RabbitMQ/">Spring Boot系列文章（五）：SpringBoot RabbitMQ 整合进阶版</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/27/SpringBoot-ActiveMQ/">Spring Boot系列文章（四）：SpringBoot ActiveMQ 整合使用</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/26/SpringBoot-RabbitMQ/">Spring Boot系列文章（三）：SpringBoot  RabbitMQ 整合使用</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/25/Docker-install/">Docker系列文章（二）：Mac 安装 Docker 及常用命令</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/24/mac/">MacBook Pro 初体验</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/17/SpringBoot-Admin/">Spring Boot系列文章（二）：SpringBoot Admin 使用指南</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/09/lombok/">Lombok 看这篇就够了</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/05/SpringBoot-Kafka/">Spring Boot系列文章（一）：SpringBoot Kafka 整合使用</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/04/Kafka/">Kafka 安装及快速入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/04/weixin/">为什么要重新运营以前的公众号呢？</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/27/consul-install/">Windows 下安装 Consul</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/25/ELK/">Elasticsearch 系列文章（五）：ELK 实时日志分析平台环境搭建</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/18/hexo-yilia/">Hexo + yilia 搭建博客可能会遇到的所有疑问</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/13/Google-Developer-Days/">谷歌开发者大会收获满满，不去真 “可惜” 了</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/09/CodeMirror/">使用 CodeMirror 打造属于自己的在线代码编辑器</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/08/netty-01-env/">Netty系列文章（一）：Netty 源码阅读之初始环境搭建</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/03/RestTemplate/">RestTemplate 详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/02/wx-01/">实习圈群里提问小记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/11/26/Docker-harbor/">Docker系列文章（一）：基于 Harbor 搭建 Docker 私有镜像仓库</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/11/18/flow-control/">基于分布式环境下限流系统的设计</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/11/18/Money-management/">谈谈我的理财</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/11/11/recommended-books/">送你一份双十一剁手书单【墙裂推荐】</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/11/11/Maven-dependencies-dependencyManagement/">Maven 中 dependencies 与 dependencyManagement 的区别</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/10/28/Data-Desensitization/">小白谈数据脱敏</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/10/21/HBase-metrics/">HBase 集群监控</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/10/18/ElasticSearch-nodes-metrics/">Elasticsearch 系列文章（四）：ElasticSearch 单个节点监控</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/10/15/ElasticSearch-cluster-health-metrics/">Elasticsearch 系列文章（三）：ElasticSearch 集群监控</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/10/14/Nexus3-Maven/">Centos7 搭建最新 Nexus3 Maven 私服</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/10/14/JsonPath/">JsonPath —— JSON 解析神器</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/23/Guava-limit/">Google Guava 缓存实现接口的限流</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/17/Interview-summary/">面试过阿里等互联网大公司，我知道了这些套路</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/15/linux-lua-lfs-install/">Linux 下 lua 开发环境安装及安装 luafilesystem</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/09/Elasticsearch-install/">Elasticsearch 系列文章（二）：全文搜索引擎 Elasticsearch 集群搭建入门教程</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/08/Elasticsearch-analyzers/">Elasticsearch 系列文章（一）：Elasticsearch 默认分词器和中分分词器之间的比较及使用方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/28/recommend-books/">那些年我看过的书 —— 致敬我的大学生活 —— Say Good Bye ！</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/18/Ubuntu-install-Nginx/">Ubuntu16.10 安装 Nginx</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/11/most-success/">马云热血励志演讲《最伟大的成功》</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/08/android-projects/">源码大招：不服来战！撸这些完整项目，你不牛逼都难！</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/05/Nginx/">Nginx 基本知识快速入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/04/alibaba/">秋招第三站 —— 内推阿里（一面）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/04/yaxin/">秋招第一站 —— 亚信科技</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/04/iqiyi/">秋招第二站 —— 内推爱奇艺（一面二面）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/29/ThreadPool/">Java 线程池艺术探索</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/25/Java-performance-tuning/">Java 性能调优需要格外注意的细节</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/21/Spring-MVC03/">Spring MVC系列文章（五）：看透 Spring MVC 源代码分析与实践 ——  Spring MVC 组件分析</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/14/Spring-MVC01/">Spring MVC系列文章（三）：看透 Spring MVC 源代码分析与实践 ——  网站基础知识</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/14/Spring-MVC02/">Spring MVC系列文章（四）：看透 Spring MVC 源代码分析与实践 ——  俯视 Spring MVC</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/09/servlet/">通过源码详解 Servlet</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/28/Velocity-foreach/">Velocity 循环指令一种好的解决方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/23/java-io/">Java IO流学习超详细总结（图文并茂）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/23/AJAX/">AJAX 学习</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/20/Java-error1/">java.sql.SQLException Field 'id' doesn't have a default value</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/19/中缀表达式转换成前缀和后缀表达式这类题目的超实用解题技巧/">中缀表达式转换成前缀和后缀表达式这类题目的超实用解题技巧</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/18/Bootstrap入门需掌握的知识点（二）/">Bootstrap入门需掌握的知识点（二）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/18/Bootstrap入门需掌握的知识点（一）/">Bootstrap入门需掌握的知识点（一）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/18/循环队列的相关条件和公式/">循环队列的相关条件和公式</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/17/详解 Filter 过滤器/">详解 Filter 过滤器</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/17/blog-talk/">搭建一个博客项目后的碎碎念</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/17/详细深入分析 Java ClassLoader 工作机制/">详细深入分析 Java ClassLoader 工作机制</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/16/通过项目逐步深入了解Spring MVC（一）/">通过项目逐步深入了解Spring MVC（一）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/15/通过项目逐步深入了解Mybatis(四)/">通过项目逐步深入了解Mybatis（四）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/14/通过项目逐步深入了解Mybatis(三)/">通过项目逐步深入了解Mybatis（三）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Hexo-yilia-toc/">Hexo + yilia 主题实现文章目录</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/HashMap-Hashtable/">HashMap、Hashtable、HashSet 和 ConcurrentHashMap 的比较</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Spring MVC+Hibernate JPA搭建的博客系统项目中所遇到的坑/">Spring MVC系列文章（二）：Spring MVC+Hibernate JPA搭建的博客系统项目中所遇到的坑</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Spring MVC + Hibernate JPA + Bootstrap 搭建的博客系统/">Spring MVC系列文章（一）：Spring MVC + Hibernate JPA + Bootstrap 搭建的博客系统 Demo</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Java-Thread/">《Java 多线程编程核心技术》学习笔记及总结</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Python爬虫实战之爬取糗事百科段子/">Python爬虫实战之爬取糗事百科段子</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/通过项目逐步深入了解Mybatis(二)/">通过项目逐步深入了解Mybatis（二）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Pyspider框架 —— Python爬虫实战之爬取 V2EX 网站帖子/">Pyspider框架 —— Python爬虫实战之爬取 V2EX 网站帖子</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/MySQL-select-good/">MySQL 处理海量数据时的一些优化查询速度方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/MyBatis-foreach/">MyBatis的foreach语句详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Java连接Oracle数据库的三种连接方式/">Java连接Oracle数据库的三种连接方式</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/【字符串】判断两字符串是否互为旋转词？/">【字符串】判断两字符串是否互为旋转词？</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/【字符串】字符串逆序/">字符串</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/feiji/">记录下自己第一次坐飞机的感受</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/JVM性能调优监控工具jps、jstack、jmap、jhat、jstat等使用详解/">JVM性能调优监控工具jps、jstack、jmap、jhat、jstat等使用详解</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Java-16-lession/">《疯狂 Java 突破程序员基本功的 16 课》读书笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/奇怪的Java题：为什么128 == 128返回为False，而127 == 127会返回为True-/">奇怪的Java题：为什么128 == 128返回为False，而127 == 127会返回为True?</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/利用Github Page 搭建个人博客网站/">利用Github Page 搭建个人博客网站</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/深入分析 Java Web 中的中文编码问题/">深入分析 Java Web 中的中文编码问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/程序访问文件的几种方式/">程序访问文件的几种方式</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/深度探究Java 中 finally 语句块/">深度探究Java 中 finally 语句块</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/解决jdk1.8中发送邮件失败（handshake_failure）问题/">解决jdk1.8中发送邮件失败（handshake_failure）问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/java-var/">从对象深入分析 Java 中实例变量和类变量的区别</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/String-new/">关于String s = new String("xyz"); 创建几个对象的问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/java读取文件/">Java读取文件</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Java NIO 系列教程/">Java NIO 系列教程</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/13/Python爬虫实战之爬取百度贴吧帖子/">Python爬虫实战之爬取百度贴吧帖子</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/12/通过项目逐步深入了解Mybatis(一)/">通过项目逐步深入了解Mybatis（一）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/06/02/poetry2/"> 六月 —— 愿你做最美好的自己！</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/05/12/poetry/">最近很火的鸡汤，分享给大家</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/04/13/Hexo-yilia-changyan/">Github pages + Hexo 博客 yilia 主题使用畅言评论系统</a></li></ul>
    <script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
    <script>
        $(".post-list").addClass("toc-article");
        $(".post-list-item a").attr("target","_blank");
        $("#post-nav-button > a:nth-child(2)").click(function() {
            $(".fa-bars, .fa-times").toggle();
            $(".post-list").toggle(300);
            if ($(".toc").length > 0) {
                $("#toc, #tocButton").toggle(200, function() {
                    if ($(".switch-area").is(":visible")) {
                        $("#tocButton").attr("value", valueHide);
                        }
                    })
            }
            else {
            }
        })
    </script>



    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                &copy; 2019 zhisheng
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" >本站总访问量: 
                            <span id="busuanzi_value_site_pv"></span>
                        </span>
                    </span>
                
                
                    <span>, </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit">本文总阅读量: 
                            <span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>

    </div>
    <script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script src="/js/main.js"></script>

    <script>
        $(document).ready(function() {
            var backgroundnum = 24;
            var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
            $("#mobile-nav").css({"background-image": backgroundimg,"background-size": "cover","background-position": "center"});
            $(".left-col").css({"background-image": backgroundimg,"background-size": "cover","background-position": "center"});
        })
    </script>




	<script>
	var _hmt = _hmt || [];
	(function() {
	  var hm = document.createElement("script");
	  hm.src = "https://hm.baidu.com/hm.js?c41be5a0c9f014e977695f66c065b5d3";
	  var s = document.getElementsByTagName("script")[0]; 
	  s.parentNode.insertBefore(hm, s);
	})();
	</script>


<div class="scroll" id="scroll">
    <a href="#"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments"><i class="fa fa-comments-o"></i></a>
    <a href="#footer"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    $(document).ready(function() {
        if ($("#comments").length < 1) {
            $("#scroll > a:nth-child(2)").hide();
        };
    })
</script>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

  <script language="javascript">
    $(function() {
        $("a[title]").each(function() {
            var a = $(this);
            var title = a.attr('title');
            if (title == undefined || title == "") return;
            a.data('title', title).removeAttr('title').hover(

            function() {
                var offset = a.offset();
                $("<div id=\"anchortitlecontainer\"></div>").appendTo($("body")).html(title).css({
                    top: offset.top - a.outerHeight() - 15,
                    left: offset.left + a.outerWidth()/2 + 1
                }).fadeIn(function() {
                    var pop = $(this);
                    setTimeout(function() {
                        pop.remove();
                    }, pop.text().length * 800);
                });
            }, function() {
                $("#anchortitlecontainer").remove();
            });
        });
    });
</script>


  </div>
</body>
</html>